<?php
class Aml_Controller_Helper_Acl
{
public $acl;
public function __construct()
{
 $this->acl = new Zend_Acl();
 $this->_db = Zend_Registry::get('db');
 $this->roles= $this->_db->fetchAll("select distinct  admin_userType from  aml_admin");
 $this->resources=$this->_db->fetchAll("select distinct  component  from  aml_acl ");
 $this->previlleges=$this->_db->fetchAll("select *    from  aml_acl ");
}
public function setRoles()
{
$this->acl->addRole(new Zend_Acl_Role("guest"));


    foreach($this->roles as $roles)
    {
        $this->acl->addRole(new Zend_Acl_Role($roles["admin_userType"]));
        $this->acl->allow($roles["admin_userType"],null,"login");
        $this->acl->allow($roles["admin_userType"],null,"logout");
    }

}

public function setResources()
{
//print_r($this->resources);
/*$this->acl->add(new Zend_Acl_Resource('auth'));
$this->acl->add(new Zend_Acl_Resource('blog'));
$this->acl->add(new Zend_Acl_Resource('content'));
$this->acl->add(new Zend_Acl_Resource('contentcont'));
$this->acl->add(new Zend_Acl_Resource('error'));
$this->acl->add(new Zend_Acl_Resource('homepage'));
$this->acl->add(new Zend_Acl_Resource('index'));
$this->acl->add(new Zend_Acl_Resource('news'));
$this->acl->add(new Zend_Acl_Resource('previllege'));
$this->acl->add(new Zend_Acl_Resource('user'));*/
 //$dir = "G:/wamp/www/plsbeta/application/admin/controllers/";
 $config = new Zend_Config_Ini('../application/configs/db_config.ini', 'dev');
              $dir= $config->app->basefilepath."/application/admin/controllers/";
    $dh = opendir($dir);
    while (($file = readdir($dh)) !== false) {
          if(ctype_alnum(strtolower(substr($file,0,-14)))==1)
          {
              $this->acl->add(new Zend_Acl_Resource(strtolower(substr($file,0,-14))));
          }
          
    }
    closedir($dh);


 
}

public function setPrivilages()
{
 foreach($this->previlleges as $previllege)
    {
       if($previllege["type"]==1)
       {
           $this->acl->allow($previllege["role"],$previllege["component"],$previllege["action"]);
       }
       else
       {
           $this->acl->deny($previllege["role"],$previllege["component"],$previllege["action"]);
       }
        
    }
}
public function setAcl()
{
Zend_Registry::set("acl",$this->acl);
}
}
?>